#include "Receiver.h"

Receiver::Receiver(void)
{
	for (u32 i = 0; i < KEY_KEY_CODES_COUNT; ++i)
	{
		KeyIsDown[i] = false;
	}
}

Receiver::~Receiver(void)
{
}

bool Receiver::OnEvent(const SEvent& event)
{
	// Key state
	if(event.EventType == EET_KEY_INPUT_EVENT)
	{
		KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
	}

	// Mouse state
	if (event.EventType == EET_MOUSE_INPUT_EVENT)
	{
		switch (event.MouseInput.Event)
		{
		case EMIE_LMOUSE_PRESSED_DOWN:
			MouseState.LeftButtonDown = true;
			break;

		case EMIE_LMOUSE_LEFT_UP:
			MouseState.LeftButtonDown = false;
			break;

		case EMIE_MOUSE_MOVED:
			MouseState.Position.X = event.MouseInput.X;
			MouseState.Position.Y = event.MouseInput.Y;
			break;

		default: break;
		}
	}

    return false;
}

const Receiver::SMouseState& Receiver::getMouseState(void) const
{
	return MouseState;
}

bool Receiver::isKeyDown(EKEY_CODE keyCode) const
{
	return KeyIsDown[keyCode];
}